<template>
  <base-breadcrumb>
    <searchData :searchData="searchArr" @search="search"></searchData>

    <a-card>
      <a-button type="primary" class="mb12" icon="plus" @click="handleManage(2)" v-btnPermission="'bm_009_add_01'"> 新增上报 </a-button>
      <a-alert class="mb12" type="info" show-icon>
        <template slot="message">
          <span>
            审核金额合计(含税)(元)：
            <a>{{ statistics.auditAmount }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            累计份数：
            <a>{{ statistics.pageTotal }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            签证占产值比 %:
            <a>{{ statistics.visaPercentage }}</a>
          </span>
        </template>
      </a-alert>
      <list-table ref="table" size="default" rowKey="id" :columns="columns" :request="loadData" :alert="true" show-size-changer show-quick-jumper showPagination="auto">
        <!-- 操作 -->
        <span slot="operation" slot-scope="text, record">
          <MoreButton>
            <a @click="handleManage(0, record)" v-btnPermission="'bm_009_loo_04'">查看</a>
            <!-- 编辑 -->
            <span v-if="(record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED') && record.type != 'CONTRACT_FILE_TOTAL'" v-btnPermission="'bm_009_edi_02'">
              <a-divider type="vertical" />
              <a @click="handleManage(1, record)">编辑</a>
            </span>
            <!-- 撤销 -->
            <span v-if="record.auditStatus == 'SUBMITTED'&&selfBtnShow(record.creatorId)&&hideBuquBtn()">
              <a-divider type="vertical" />
              <a @click="handleUndo({ id: record.id, type: 3 })">撤销</a>
            </span>
            <!-- 作废 -->
            <!-- 要第四步并且提交后才可以作废 -->
            <span v-if="record.auditStatus == 'COMMIT'" v-btnPermission="'bm_009_tov_05'">
              <a-divider type="vertical" />
              <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>
            </span>
            <!-- 删除 -->
            <span v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED'" v-btnPermission="'bm_009_del_03'">
              <a-divider type="vertical" />
              <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
            </span>
            <!-- 审批信息 -->
            <span v-if="!(record.auditStatus == 'DRAFT' && record.type == 'INSTRUCTION_CONFIRM')">
              <a-divider type="vertical" />
              <approval-button :id="record.id" :status="record.auditStatus == 'DRAFT' && record.type == 'INSTRUCTION_CONFIRM' ? 'DRAFT' : 'SUBMITTED'" />
            </span>
            <!-- 资料上传 -->
            <span v-if="record.auditStatus == 'DRAFT' && record.type == 'CONTRACT_FILE_TOTAL'" v-btnPermission="'bm_009_edi_02'">
              <a-divider type="vertical" />
              <a @click="handleManage(1, record)">资料上传</a>
            </span>
          </MoreButton>
        </span>
        <template slot="auditStatus" slot-scope="text, record">
          <statusList :status="record.auditStatus"></statusList>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { getList, getStatistical, delSubcontractVisa } from '@/api/businessAffairs/subcontractVisa'

import MoreButton from '@/components/MoreButton'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractorCode from '@/components/Select/SelectSubcontractorCode' // 分包商
import { STable } from '@/components'
import statusList from './components/statusList.vue'
import { stepList, typeListApproval } from './model.js'
import BasePage from '@/views/basePage' // 基础配置
const searchArr = [
{
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '所属分公司',
  //   valueKey: 'branchComId',
  //   type: SelectSubCompany
  // },
  // {
  //   name: '所属项目',
  //   keyValue: 'branchComId',
  //   valueKey: 'projectId',
  //   type: SelectProject
  // },
  {
    name: '分包商名称',
    type: 'input',
    value: 'subContractUnitName'
  },
  {
    name: '合同名称',
    type: 'input',
    value: 'contractName'
  },
  {
    name: '施工部位',
    value: 'constructionSite',
    type: 'input'
  },
  {
    name: '填报人',
    value: 'creatorName',
    type: 'input'
  },
  {
    name: '填报时间',
    type: 'dateRange',
    value: 'activityDate',
    attr: {
      rangeFormat: ['createTimeBegin', 'createTimeEnd']
    }
  },

  {
    name: '状态',
    value: 'auditStatus',
    type: 'select',
    data: typeListApproval
  },
  {
    name: '步骤',
    value: 'type',
    type: 'select',
    data: stepList
  }
]
const columns = [
  {
    title: '名称',
    dataIndex: 'name',
    ellipsis: true
  },

  {
    title: '分包单位',
    dataIndex: 'subContractUnitName',
    ellipsis: true
  },
  {
    title: '合同名称',
    dataIndex: 'contractName',
    ellipsis: true
  },
  {
    title: '所属分公司',
    dataIndex: 'branchComName',
    ellipsis: true
  },
  {
    title: '所属项目',
    dataIndex: 'projectName',
    ellipsis: true
  },
   {
    title: '报送金额',
    dataIndex: 'initialVisaTotal',
    ellipsis: true
  },
   {
    title: '审核金额',
    dataIndex: 'initialVisaTotalEnd',
    ellipsis: true
  },
  {
    title: '填报人',
    dataIndex: 'creatorName',
    ellipsis: true
  },
  {
    title: '填报时间',
    dataIndex: 'createTime'
  },
  {
    title: '分包签证步骤',
    dataIndex: 'typeStr'
  },

  {
    title: '状态',
    dataIndex: 'auditStatus',
    scopedSlots: { customRender: 'auditStatus' }
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '200px',
    scopedSlots: { customRender: 'operation' }
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    SelectSubCompany,
    SelectProject,
    SelectSubcontractorCode,
    STable,
    MoreButton,
    statusList
  },

  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {},
      statistics: {
        auditAmount: 0,
        pageTotal: 0,
        visaPercentage: 0
      }, //统计
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        this.getStatistical(requestParameters)
        return getList(requestParameters).then((res) => {
          console.log('数据返回对象：', res)
          return res
        })
      },
      removeApi: { remove: delSubcontractVisa, invalid: delSubcontractVisa, undo: delSubcontractVisa } // api
    }
  },

  methods: {
    getStatistical(requestParameters) {
      getStatistical(requestParameters).then((res) => {
        this.statistics = res.data
      })
    },

    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'updateProjectSubcontractVisa',
        query
      })
    }
  }
}
</script>

<style lang="less">
.not-submit {
  display: inline-block;
  padding: 0;
  li {
    list-style: disc;
    color: red;
  }
}
.submitted {
  display: inline-block;
  padding: 0;
  li {
    list-style: disc;
    color: green;
  }
}
.alert-info {
  width: 100%;
  background-color: #e6f7ff;
  padding: 16px 0;
  margin-top: 10px;
  border-radius: 10px;
  .info-icon {
    margin: 0 6px 0 12px;
  }
  span {
    margin-right: 5px;
    color: #1890ff;
  }
}
</style>
